package com.example.message.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.message.entity.Summary;
import com.example.message.service.SummaryService;
import com.example.message.service.Task1Service;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/summary")
public class SummaryController {

    private final SummaryService summaryService;
    private final Task1Service taskService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param summary 数据源表
     * @return
     */
    @GetMapping("/page" )
    public R<IPage> getGenDatasourceConfPage(Page page, Summary summary) {
        return R.ok(summaryService.page(page, Wrappers.query(summary)));
    }

    /**
     * 通过id查询数据源表
     * @param id id
     * @return R
     */
    @GetMapping("/{id}" )
    public R getById(@PathVariable("id" ) Integer id) {
        return R.ok(summaryService.getById(id));
    }

    /**
     * 新增数据源表
     * @param summary 数据源表
     * @return R
     */
    @PostMapping
    public R save(@RequestBody Summary summary) {
        System.out.println("aa:"+summary.toString());
        return R.ok(summaryService.save(summary));
    }

    /**
     * 修改数据源表
     * @param summary 数据源表
     * @return R
     */
    @PutMapping
    public R updateById(@RequestBody Summary summary) {
        return R.ok(summaryService.updateById(summary));
    }

    /**
     * 通过id删除数据源表
     * @param id id
     * @return R
     */
    @DeleteMapping("/{id}" )
    public R removeById(@PathVariable Integer id) {
        return R.ok(summaryService.removeById(id));
    }


}
